//
//  SRModifyPersonalBirthdayView.m
//  SportRing
//
//  Created by icelee on 14-10-31.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRModifyPersonalBirthdayView.h"
#import "SRDB.h"

@interface SRModifyPersonalBirthdayView()

@property (nonatomic, weak)IBOutlet UIDatePicker *birthdayPicker;

@end

@implementation SRModifyPersonalBirthdayView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    _birthdayPicker.datePickerMode = UIDatePickerModeDate;
    
    _birthdayPicker.date = _birthDayDate ? _birthDayDate : [NSDate date];

    _birthdayPicker.maximumDate = [NSDate date];
    
    [_birthdayPicker addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventValueChanged];
    
    _birthDayDate = [NSDate date];
}

- (void)setBirthDayDate:(NSDate *)birthDayDate
{
    if (_birthDayDate == birthDayDate) {
        return;
    }
    _birthDayDate = birthDayDate;
    
    _birthdayPicker.date = _birthDayDate ? _birthDayDate : [NSDate date];
    
}

+ (SRModifyPersonalBirthdayView*)LoadSRModifyPersonalBirthdayView
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SRModifyPersonalBirthdayView" owner:self options:nil];
    
    return [nib objectAtIndex:0];
}


- (void)selectedDate:(id)sender
{
    UIDatePicker *picker = (UIDatePicker *)sender;
    self.birthDayDate = picker.date;
    [[SRMe currentUser] configAttributesWithBlock:^(SRMe *meSelf) {
        meSelf.birthday = [picker.date formattedBy_yyyyMMdd];
    }];
}

@end
